//
//  researchViewController.m
//  Project
//
//  Created by iD Student on 7/30/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "researchViewController.h"

@interface researchViewController ()

@end

@implementation researchViewController
@synthesize researchInfo;
@synthesize resourceButton;
@synthesize researchScroll;
@synthesize fastGatheringOwned;
@synthesize cheapTroopsOwned;
@synthesize raidingOwned;
@synthesize valiantSoldiersOwned;
@synthesize cityBarricadeOwned;
@synthesize woodCount;
@synthesize stoneCount;
@synthesize ironCount;
@synthesize researchHelp1;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    researchInfo.hidden = TRUE;
    resourceButton.hidden = TRUE;
    researchScroll.hidden = TRUE;
    
    woodCount.text = [NSString stringWithFormat:@"%d", wood];
    stoneCount.text = [NSString stringWithFormat:@"%d", stone];
    ironCount.text = [NSString stringWithFormat:@"%d", iron];
    
    if (fastGathering == TRUE)
    {
        fastGatheringOwned.text = @"Owned";
    }
    else 
    {
        fastGatheringOwned.text = @"Not owned";
    }
    if (cheapTroops == TRUE)
    {
        cheapTroopsOwned.text = @"Owned";
    }
    else 
    {
        cheapTroopsOwned.text = @"Not owned";
    }
    if (raiding == TRUE)
    {
        raidingOwned.text = @"Owned";
    }
    else 
    {
        raidingOwned.text = @"Not owned";
    }
    if (valiantSoldiers == TRUE)
    {
        valiantSoldiersOwned.text = @"Owned";
    }
    else 
    {
        valiantSoldiersOwned.text = @"Not owned";
    }
    if (cityBarricade == TRUE)
    {
        cityBarricadeOwned.text = @"Owned";
    }
    else 
    {
        cityBarricadeOwned.text = @"Not owned";
    }
    
    [super viewDidLoad];
	// Do any additional setup after loading the view.
}

- (void)viewDidUnload
{
    [self setWoodCount:nil];
    [self setStoneCount:nil];
    [self setIronCount:nil];
    [self setFastGatheringOwned:nil];
    [self setCheapTroopsOwned:nil];
    [self setRaidingOwned:nil];
    [self setValiantSoldiersOwned:nil];
    [self setCityBarricadeOwned:nil];
    [self setResearchInfo:nil];
    [self setResourceButton:nil];
    [self setResearchScroll:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (IBAction)back:(id)sender 
{
    [self dismissModalViewControllerAnimated:YES];
}
- (void)dealloc {
    [woodCount release];
    [stoneCount release];
    [ironCount release];
    [fastGatheringOwned release];
    [cheapTroopsOwned release];
    [raidingOwned release];
    [valiantSoldiersOwned release];
    [cityBarricadeOwned release];
    [researchInfo release];
    [resourceButton release];
    [researchScroll release];
    [super dealloc];
}
- (IBAction)fastGatheringBuy:(id)sender 
{
    if (inforesearch1 == FALSE)
    {
        researchInfo.hidden = FALSE;
        resourceButton.hidden = FALSE;
        researchScroll.hidden = FALSE;
        researchInfo.text = @"By researching this, you gain a significant boost to your resource building production.";
        inforesearch1 = TRUE;
    }
    else
    {
    if (fastGathering == FALSE && wood >= 800 && stone >= 500 && iron >= 500)
    {
        fastGathering = TRUE;
        fastGatheringOwned.text = @"Owned";
        wood = wood - 800;
        stone = stone - 500;
        iron = iron - 500;
        woodCount.text = [NSString stringWithFormat:@"%d", wood];
        stoneCount.text = [NSString stringWithFormat:@"%d", stone];
        ironCount.text = [NSString stringWithFormat:@"%d", iron];
    }
    }
}

- (IBAction)cheapTroopsBuy:(id)sender 
{
    if (inforesearch2 == FALSE)
    {
        researchInfo.hidden = FALSE;
        resourceButton.hidden = FALSE;
        researchScroll.hidden = FALSE;
        researchInfo.text = @"By researching this, you can purchase soldiers for lower costs.";
        inforesearch2 = TRUE;
    }
    else
    {
    if (cheapTroops == FALSE && wood >= 700 && stone >= 600 && iron >= 1200)
    {
        cheapTroops = TRUE;
        cheapTroopsOwned.text = @"Owned";
        wood = wood - 700;
        stone = stone - 600;
        iron = iron - 1200;
        woodCount.text = [NSString stringWithFormat:@"%d", wood];
        stoneCount.text = [NSString stringWithFormat:@"%d", stone];
        ironCount.text = [NSString stringWithFormat:@"%d", iron];
    }
    }
}

- (IBAction)raidingBuy:(id)sender 
{
    if (inforesearch3 == FALSE)
    {
        researchInfo.hidden = FALSE;
        resourceButton.hidden = FALSE;
        researchScroll.hidden = FALSE;
        researchInfo.text = @"By researching this, you gain a significant attack bonus and plundering bonus.";
        inforesearch3 = TRUE;
    }
    else
    {
    if (raiding == FALSE && wood >= 2000 && stone >= 2000 && iron >= 2200)
    {
        raiding = TRUE;
        raidingOwned.text = @"Owned";
        wood = wood - 2000;
        stone = stone - 2000;
        iron = iron - 2200;
        woodCount.text = [NSString stringWithFormat:@"%d", wood];
        stoneCount.text = [NSString stringWithFormat:@"%d", stone];
        ironCount.text = [NSString stringWithFormat:@"%d", iron];
    }
    }
}

- (IBAction)valiantSoldiersBuy:(id)sender 
{
    if (inforesearch4 == FALSE)
    {
        researchInfo.hidden = FALSE;
        resourceButton.hidden = FALSE;
        researchScroll.hidden = FALSE;
        researchInfo.text = @"By researching this, your soldiers gain a slight offensive and defensive boost.";
        inforesearch4 = TRUE;
    }
    else
    {
    if (valiantSoldiers == FALSE && wood >= 1200 && stone >= 1200 && iron >= 1200)
    {
        valiantSoldiers = TRUE;
        valiantSoldiersOwned.text = @"Owned";
        wood = wood - 1200;
        stone = stone - 1200;
        iron = iron - 1200;
        woodCount.text = [NSString stringWithFormat:@"%d", wood];
        stoneCount.text = [NSString stringWithFormat:@"%d", stone];
        ironCount.text = [NSString stringWithFormat:@"%d", iron];
    }
    }
}

- (IBAction)cityBarricadeBuy:(id)sender 
{
    if (inforesearch5 == FALSE)
    {
        researchInfo.hidden = FALSE;
        resourceButton.hidden = FALSE;
        researchScroll.hidden = FALSE;
        inforesearch5 = TRUE;
        researchInfo.text = @"By researching this, your soldiers gain a significant defensive boost";
    }
    else
    {
    if (cityBarricade == FALSE && wood >= 1000 && stone >= 2500 && iron >= 1000)
    {
        cityBarricade = TRUE;
        cityBarricadeOwned.text = @"Owned";
        wood = wood - 1000;
        stone = stone - 2500;
        iron = iron - 1000;
        woodCount.text = [NSString stringWithFormat:@"%d", wood];
        stoneCount.text = [NSString stringWithFormat:@"%d", stone];
        ironCount.text = [NSString stringWithFormat:@"%d", iron];
    }
    }
}
- (IBAction)help:(id)sender 
{
    researchHelp1 = [self.storyboard instantiateViewControllerWithIdentifier:@"researchHelp1"];
    [self presentModalViewController: researchHelp1 animated:YES];
}

- (IBAction)resourceButton:(id)sender 
{
    researchInfo.hidden = TRUE;
    resourceButton.hidden = TRUE;
    researchScroll.hidden = TRUE;
}
@end
